/**
  ******************************************************************************
  * @file    bsp_iap_flash.h
  * @author  Iron
  * @date    2018-07-09
  * @version v1.0
  * @brief   bsp_iap_flash header file
  */

#ifndef __BSP_IAP_H
#define __BSP_IAP_H

#ifdef __cplusplus
extern "C" {
#endif

/* includes ------------------------------------------------------------------*/
#include <stdint.h>

/* exported types ------------------------------------------------------------*/
/* exported constants --------------------------------------------------------*/

#define BSP_MCU_FLASH_START_ADDRESS  0x08000000
#define BSP_MCU_FLASH_SIZE           0x100000
#define BSP_MCU_FLASH_END_ADDRESS    (BSP_MCU_FLASH_START_ADDRESS + BSP_MCU_FLASH_SIZE)

/* Error code */
enum
{
    BSP_IAP_OK = 0,
    BSP_IAP_ERASE_OK,
    BSP_IAP_ERASE_ERROR,
    BSP_IAP_WRITINGCTRL_ERROR,
    BSP_IAP_WRITING_ERROR
};

enum
{
    BSP_IAP_PROTECTION_NONE         = 0x00,
    BSP_IAP_PROTECTION_PCROPENABLED = 0x01,
    BSP_IAP_PROTECTION_WRPENABLED   = 0x02,
    BSP_IAP_PROTECTION_RDPENABLED   = 0x04,
};

/* exported macro ------------------------------------------------------------*/
/* exported functions ------------------------------------------------------- */
void bsp_iap_flash_init(void);
void bsp_iap_flash_deinit(void);

uint32_t bsp_iap_flash_erase(uint32_t user_flash_address, uint32_t user_flash_size);
uint32_t bsp_iap_flash_write(uint32_t flash_address, const uint8_t *data, uint32_t datalen);

uint16_t bsp_iap_flash_get_write_protection_status(void);
int bsp_ipa_flash_write_protection_config(uint32_t modifier);

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __BSP_IAP_H */

/******************* (C)COPYRIGHT 2018 ***** END OF FILE *********************/
